-
Notifications
You must be signed in to change notification settings - Fork 9
/
PDFBuild+Chords.swift
50 lines (43 loc) · 1.68 KB
/
PDFBuild+Chords.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// PDFBuild+Chords.swift
// Chord Provider
//
// © 2024 Nick Berendsen
//
import Foundation
import SwiftlyChordUtilities
extension PDFBuild {
// MARK: A PDF **chords** element
/// A PDF **chords** element
///
/// Display all the chord diagrams of the song
class Chords: PDFElement {
/// All the chords from the song
let chords: [ChordDefinition]
/// The chord display options
let options: ChordDefinition.DisplayOptions
/// Init the **chords** element
/// - Parameters:
/// - chords: All the chords from the song
/// - options: The chord display options
init(chords: [ChordDefinition], options: ChordDefinition.DisplayOptions) {
self.chords = chords
.sorted(using: KeyPathComparator(\.root))
.sorted(using: KeyPathComparator(\.quality))
self.options = options
}
/// Draw the **chords** element as a `Section` element
/// - Parameters:
/// - rect: The available rectangle
/// - calculationOnly: Bool if only the Bounding Rect should be calculated
/// - pageRect: The page size of the PDF document
func draw(rect: inout CGRect, calculationOnly: Bool, pageRect: CGRect) {
var items: [PDFElement] = []
for chord in chords where chord.status != .unknownChord {
items.append(Diagram(chord: chord, options: options))
}
let chords = PDFBuild.Section(columns: [SectionColumnWidth].init(repeating: .flexible, count: 7), items: items)
chords.draw(rect: &rect, calculationOnly: calculationOnly, pageRect: pageRect)
}
}
}